/**
 * 
 */
package com.common.bean;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.common.StarAppConst.IM_MESSAGE_KEY;
import com.common.allCommon.JSONObjecthelper;

/**
 * 【IM消息】A请求为好友消息数据存储类 <br>
 * Created 2014-11-6 下午4:45:26
 * 
 * @version
 * @author ChuXY
 * 
 * @see
 */

public class FriendRequestedData extends AppMsgData implements
		ICommonImDataStruct, Parcelable,ICommonIMFriendInfo {

	/** 消息类型 */
	private String mType = "";

	/**
	 * 请求消息内容
	 */
	private String mMessage = "";

	/** 时间戳 */
	private long mTime = 0;

	/** 请求用户昵称 */
	private String mFriendUniqueName = "";

	/** 请求用户id */
	private long mFriendUid = 0;

	/**朋友头像id*/
	private long mFriendFileId=0;
	/** 请求验证信息 */
	private String mRequestMessage = "";

	@Override
	public void parseJson(String strJson) {
		if (TextUtils.isEmpty(strJson)) {
			return;
		}

		JSONObject jsonData = null;
		try {
			jsonData = new JSONObject(strJson);
		} catch (JSONException e) {
			return;
		}
		mType = JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_TYPE);
		mMessage = JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_MSG);
		mTime = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_TIME);
		mFriendUid = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_FRIENDTID);
		mFriendUniqueName = JSONObjecthelper.getString(jsonData,
				IM_MESSAGE_KEY.TAG_FRIEND_UNIQUENAME);
		mFriendFileId=JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_FRIEND_CHECK_CODE);
		mRequestMessage=JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_REQUEST_MSG);
	}

	/**
	 * @return the mRequestMessage
	 */
	public String getRequestMessage() {
		return mRequestMessage;
	}

	/**
	 * @param mRequestMessage
	 *            the mRequestMessage to set
	 */
	public void setRequestMessage(String requestMessage) {
		this.mRequestMessage = requestMessage;
	}

	@Override
	public String getType() {
		return mType;
	}

	@Override
	public void setType(String type) {
		mType = type;
	}

	@Override
	public String getMessage() {
		return mMessage;
	}

	@Override
	public void setMessage(String message) {
		mMessage = message;
	}

	@Override
	public long getTime() {
		return mTime;
	}

	@Override
	public void setTime(long time) {
		mTime = time;
	}

	@Override
	public String getFriendUniqueName() {
		return mFriendUniqueName;
	}

	@Override
	public void setFriendUniqueName(String uniqueName) {
		mFriendUniqueName = uniqueName;
	}

	@Override
	public long getFriendUid() {
		return mFriendUid;
	}

	@Override
	public void setFriendUid(long uid) {
		mFriendUid = uid;
	}

	@Override
	public String transDataToJSON() {
		JSONObject json = new JSONObject();
		try {
			json.put(IM_MESSAGE_KEY.TAG_TYPE, mType);
			json.put(IM_MESSAGE_KEY.TAG_MSG, mMessage);
			json.put(IM_MESSAGE_KEY.TAG_TIME, mTime);
			json.put(IM_MESSAGE_KEY.TAG_FRIEND_UNIQUENAME, mFriendUniqueName);
			json.put(IM_MESSAGE_KEY.TAG_FRIENDTID, mFriendUid);
			json.put(IM_MESSAGE_KEY.TAG_REQUEST_MSG, mRequestMessage);
			json.put(IM_MESSAGE_KEY.TAG_FRIEND_CHECK_CODE, mFriendFileId);

		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		return json.toString();
	}

	@Override
	public void setDataFromJSON(String jsonString) {
		parseJson(jsonString);
	}

	/**
	 * Creates a new instance of UserUpdateData. <br>
	 * Created 2014-11-3 下午3:17:45
	 * 
	 * @param in
	 */
	public FriendRequestedData(Parcel in) {
		mMessage = in.readString();
		mTime = in.readLong();
		mType = in.readString();
		mFriendUniqueName = in.readString();
		mFriendUid = in.readLong();
		mRequestMessage = in.readString();
		mFriendFileId=in.readLong();
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(mMessage);
		dest.writeLong(mTime);
		dest.writeString(mType);
		dest.writeString(mFriendUniqueName);
		dest.writeLong(mFriendUid);
		dest.writeString(mRequestMessage);
		dest.writeLong(mFriendFileId);
	}

	public static final Parcelable.Creator<FriendRequestedData> CREATOR = new Creator<FriendRequestedData>() {

		@Override
		public FriendRequestedData[] newArray(int size) {
			return new FriendRequestedData[size];
		}

		@Override
		public FriendRequestedData createFromParcel(Parcel in) {
			return new FriendRequestedData(in);
		}
	};

	
	/**
	 * Creates a new instance of FriendRequestedData.
	 * <br>Created 2014-11-6 下午5:50:34
	 */
	
	public FriendRequestedData() {
		super();
	}

	@Override
	public long getFileId() {
		return mFriendFileId;
	}

	@Override
	public void setFileId(long fileId) {
		mFriendFileId=fileId;
	}

	
	@Override
	public void setFriendFileId(long fid) {
		mFriendFileId=fid;
	}

	
	@Override
	public long getFriendFileId() {
		return mFriendFileId;
	}
	
	@Override
	public String getUniqueName() {
		return null;
	}

	@Override
	public void setUniqueName(String uniqueName) {
		
	}

	
	@Override
	public long getUid() {
		return 0;
	}

	
	@Override
	public void setUid(long uid) {
		
	}

	
	@Override
	public long getLongExtraData() {
		return 0;
	}

	/**
	 * 
	 * <br>Created 2014-11-30 下午4:08:32
	 * @return
	 * @author       ChuXY	
	*/
	
	@Override
	public String getStringExtraData() {
		// TODO Auto-generated method stub
		return null;
	}

	
}
